package cn.cvs.service.supplier;

import cn.cvs.pojo.Supplier;
import cn.cvs.service.sysUser.SysUserTest;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Date;
import java.util.List;

import static org.junit.Assert.*;

public class SupplierTest {
    private Logger logger = Logger.getLogger(SupplierTest.class);

    @Before
    public void setUp() throws Exception {
    }

    @Test
    public void testGetSupplierList() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml","applicationContext-dao.xml","applicationContext-service.xml");
        SupplierService supplierService = (SupplierService) applicationContext.getBean("supplierService");
        List<Supplier> list = supplierService.getList();

        for (Supplier supplier : list) {
            logger.debug(supplier.toString());
        }
    }

    @Test
    public void testGetSupplierNameList() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        SupplierService supplierService = (SupplierService) applicationContext.getBean("supplierService");
        Supplier supplier = new Supplier();
        supplier.setSupName("公司");
        List<Supplier> list = supplierService.selectSupplierNameList(supplier);

        for (Supplier s : list) {
            logger.debug(s.toString());
        }
    }

    @Test
    public void testAdd() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        SupplierService supplierService = (SupplierService) applicationContext.getBean("supplierService");
        Supplier supplier = new Supplier();
        supplier.setSupCode("BJ_GYS002");
        supplier.setSupName("anan科技有限公司");
        supplier.setSupDesc("主营产品:服装、帽子");
        supplier.setSupContact("安安");
        supplier.setSupPhone("13323566541");
        supplier.setSupAddress("湖南省郴州市");
        supplier.setSupFax("0311-6773887");
        supplier.setCreatedUserId(1);
        supplier.setCreatedTime(new Date());
        int result = supplierService.add(supplier);
        logger.debug("textAdd result:" + result);
    }

    @Test
    public void testDel() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        SupplierService supplierService = (SupplierService) applicationContext.getBean("supplierService");
        int id = 18;
        int result = supplierService.del(id);
        logger.debug("textDel result:" + result);
    }

    @Test
    public void testUpd() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        SupplierService supplierService = (SupplierService) applicationContext.getBean("supplierService");
        Integer id = 17;
        String supCode = "SB_GYS002";
        String supName = "花花科技有限公司";
        String supDesc = "主营产品：沐浴露、洗发露、护发素等日化品批销";
        String supContact = "花花";
        String supPhone = "13422235679";
        String supAddress = "江苏省南京市浦口区浦口大道";
        String supFax = "0556-34441010";
        Integer updatedUserId = 1;
        Date updatedTime = new Date();
        Supplier supplier = new Supplier();
        supplier.setId(id);
        supplier.setSupCode(supCode);
        supplier.setSupName(supName);
        supplier.setSupDesc(supDesc);
        supplier.setSupContact(supContact);
        supplier.setSupPhone(supPhone);
        supplier.setSupAddress(supAddress);
        supplier.setSupFax(supFax);
        supplier.setUpdatedUserId(updatedUserId);
        supplier.setUpdatedTime(updatedTime);
        int result = supplierService.upd(supplier);
        logger.debug("testUpd result:" + result);
    }
}